import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../../../../resource/language/generated/l10n.dart';
import '../../interface/root_proxy_model.dart';
import 'user_list_cash_page_model.dart';

class UserListCashPage extends StatelessWidget {
  int initCashIndex;

  UserListCashPage({this.initCashIndex = 0, Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MultiProvider(
        providers: [
          ChangeNotifierProxyProvider<RootProxyModel, UserListPageCashModel>(
            create: (context) => UserListPageCashModel(initCashIndex),
            update: (context, rootProxyModel, leafModel) {
              if (leafModel == null) throw ArgumentError.notNull('leafModel');
              leafModel.roomModel = rootProxyModel;
              return leafModel;
            },
          ),
        ],
        child:
            Consumer<UserListPageCashModel>(builder: (context, model, child) {
          return Stack(
            children: [
              Column(
                children: [
                  SizedBox(
                    height: 23,
                  ),
                  Container(
                    height: 36,
                    decoration: BoxDecoration(
                      color: Color(0xfff6f7f9),
                      borderRadius: BorderRadius.circular(18),
                    ),
                    padding: EdgeInsets.symmetric(vertical: 3),
                    child: Row(
                      mainAxisSize: MainAxisSize.min,
                      children: [
                        getTitleWidget(
                            T.current.day_rank_list, model.currentIndex == 0,
                            () {
                          model.selectItem(0);
                        }),
                        getTitleWidget(
                            T.current.week_rank_list, model.currentIndex == 1,
                            () {
                          model.selectItem(1);
                        }),
                        getTitleWidget(
                            T.current.month_rank_list, model.currentIndex == 2,
                            () {
                          model.selectItem(2);
                        }),
                      ],
                    ),
                  ),
                  SizedBox(
                    height: 10,
                  ),

                  Container(
                    color: Colors.red,
                    child: Text('ListView.builder'),
                  ),

                  // Expanded(
                  //   child: ListView.builder(
                  //       itemCount:
                  //           model.dataMap[model.currentIndex]?.users.length ??
                  //               0,
                  //       itemBuilder: (context, index) {
                  //         return UserListItemWidget(
                  //           user:
                  //               model.dataMap[model.currentIndex]!.users[index],
                  //           index: index,
                  //           tabIndex: 1,
                  //           onPressed: () {
                  //             model.onItemPressed(
                  //                 context,
                  //                 model.dataMap[model.currentIndex]!
                  //                     .users[index]);
                  //           },
                  //         );
                  //       }),
                  // ),
                  const SizedBox(
                    height: 72,
                  ),
                ],
              ),
              // Positioned(
              //     left: 0,
              //     right: 0,
              //     bottom: 0,
              //     child: model.dataMap[model.currentIndex]?.myself != null
              //         ? UserListMySelfItemWidget(
              //             user: model.dataMap[model.currentIndex]!.myself,
              //             lastUser: model.lastUser,
              //             isRanking: model.isCurrUserRanking,
              //           )
              //         : Container())
            ],
          );
        }));
  }

  Widget getTitleWidget(String title, bool isSelected, VoidCallback onPressed) {
    return CupertinoButton(
      onPressed: onPressed,
      padding: EdgeInsets.zero,
      minSize: 0,
      child: Container(
        width: 71,
        height: 30,
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(15),
          color: isSelected ? Color(0xffffd400) : Colors.transparent,
        ),
        alignment: Alignment.center,
        child: Text(
          title,
          style: TextStyle(
              fontSize: 15,
              color: isSelected ? Color(0xff333333) : Color(0xff999999),
              height: 1,
              fontWeight: isSelected ? FontWeight.w500 : FontWeight.w400),
        ),
      ),
    );
  }
}
